using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;

public partial class LeftControl : System.Web.UI.UserControl
{
    #region Viarible
    public int NoCountStart
    {
        get { return Convert.ToInt32(ViewState["NoCountStart"]); }
        set { ViewState["NoCountStart"] = value; }
    }
    int CountArticle = 0;
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadSession();
        LoadTraceShow();
        LoadFeatureCountry();
    }
    #region LoadSession
    private void LoadSession()
    {
        if (Session["MemberId"] != null)
        {
            mid_sign_in.Visible = false;
            mid_sign_out.Visible = true;
        }
        else
            mid_sign_out.Visible = false;
    }

    #endregion
    #region Load Trace Show
    private void LoadTraceShow()
    {
        int total = 0;
        Criteria cri = new Criteria();
        cri.addJoin(ArticleSubCat._Table, "[" + Article._Table + "].[" + ArticleColumns.SubCatId + "]", "[" + ArticleSubCat._Table + "].[" + ArticleSubCatColumns.SubCategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.addJoin(ArticleCat._Table, "[" + ArticleSubCat._Table + "].[" + ArticleSubCatColumns.CategoryID + "]", "[" + ArticleCat._Table + "].[" + ArticleCatColumns.CategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.add(ArticleCat._Table + "." + ArticleCatColumns.Code, FetConstant.Tradeshow, Condition.EQUAL, Condition.AND);
        cri.add(Article._Table + "." + ArticleColumns.Status, 2, Condition.EQUAL, Condition.AND);
        ArticleCollection _Articlecon = ArticleService.GetArticleListByParam("[" + Article._Table + "].[" + ArticleColumns.Order + "]," + "[" + Article._Table + "].[" + ArticleColumns.CreatedDate + "]", OrderDirection.DESC, 1, 2, cri.Criter, out total);
        if (_Articlecon.Count > 0)
        {
            rptTraceShow.DataSource = _Articlecon;
            rptTraceShow.DataBind();

        }

    }
    protected void rptTraceShow_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Article _Article = (Article)e.Item.DataItem;
            HtmlAnchor ahrTitle = (HtmlAnchor)e.Item.FindControl("ahrTitle");
            Literal ltrTitle = (Literal)e.Item.FindControl("ltrTitle");
            Literal ltrDate = (Literal)e.Item.FindControl("ltrDate");
            Literal ltrSum = (Literal)e.Item.FindControl("ltrSum");

            ltrTitle.Text = _Article.Title;
            ltrSum.Text = _Article.Summary;
            ltrDate.Text = Utility.GetFormattedDate(_Article.CreatedDate);



        }
    }
    #endregion
    #region Load Feature country
    private void LoadFeatureCountry()
    {
        int total = 0;
        Criteria cri = new Criteria();
        cri.addJoin(ArticleSubCat._Table, "[" + Article._Table + "].[" + ArticleColumns.SubCatId + "]", "[" + ArticleSubCat._Table + "].[" + ArticleSubCatColumns.SubCategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.addJoin(ArticleCat._Table, "[" + ArticleSubCat._Table + "].[" + ArticleSubCatColumns.CategoryID + "]", "[" + ArticleCat._Table + "].[" + ArticleCatColumns.CategoryID + "]", Condition.EQUAL, Condition.LEFT_JOIN);
        cri.add(ArticleCat._Table + "." + ArticleCatColumns.Code, FetConstant.Featurecountry, Condition.EQUAL, Condition.AND);
        cri.add(Article._Table + "." + ArticleColumns.Status, 2, Condition.EQUAL, Condition.AND);
        ArticleCollection _Articlecon = ArticleService.GetArticleListByParam("[" + Article._Table + "].[" + ArticleColumns.Order + "]," + "[" + Article._Table + "].[" + ArticleColumns.CreatedDate + "]", OrderDirection.DESC, 1, 4, cri.Criter, out total);
        if (_Articlecon.Count > 0)
        {
            CountArticle = _Articlecon.Count;
            Article _Article = _Articlecon[0];
            ltrTitleFeatureCountry.Text = _Article.Title;
            if (!string.IsNullOrEmpty(_Article.Image))
                imgFeatureCountry.Src = "photos/" + _Article.Image;
            _Articlecon.RemoveAt(0);
            rptFeatureCountry.DataSource = _Articlecon;
            rptFeatureCountry.DataBind();

        }

    }
    protected void rptFeatureCountry_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Article _Article = (Article)e.Item.DataItem;
            HtmlAnchor ahrTitle = (HtmlAnchor)e.Item.FindControl("ahrTitle");
            Literal ltrTitle = (Literal)e.Item.FindControl("ltrTitle");
            HtmlControl divline_trade_show = (HtmlControl)e.Item.FindControl("divline_trade_show");
            ltrTitle.Text = _Article.Title;
            ahrTitle.HRef = "Detail-" + _Article.ArticleId.ToString() + "-" + Utilitys.StripDiacritics(Utility.Splitword(_Article.Title)) + ".aspx";
            int STT = NoCountStart + e.Item.ItemIndex;
            if (STT == CountArticle - 2)
            {
                divline_trade_show.Visible = false;
            }


        }
    }
    #endregion
}
